package cn.mandifal.search.service.impl;

import cn.mandifal.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;
import java.util.Arrays;

/**
 * 从 solr 库中删除商品的 activemq 监听类
 * @author
 */
@Component
public class GoodsDeleteListener implements MessageListener {
    @Autowired
    private SearchService searchService;
    @Override
    public void onMessage(Message message) {
        ObjectMessage objectMessage = (ObjectMessage) message;
        try {
            System.out.println("------------ 删除 solr 库中特定数据 -------------");
            Long[] goodsIds= (Long[]) objectMessage.getObject();
            searchService.deleteByGoodsIds(Arrays.asList(goodsIds));
            System.out.println("------------ 删除 solr 库中特定数据成功 -------------");
        } catch (JMSException e) {
            e.printStackTrace();
        }
    }
}
